package com.ktg.mes.chanjet.controller;

import com.chanjet.openapi.sdk.java.exception.ChanjetApiException;
import com.ktg.common.core.domain.Result;
import com.ktg.mes.chanjet.common.Constants;
import com.ktg.mes.chanjet.spi.ChanjetSpi;
import com.ktg.mes.unit.other.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/chanjet/auth")
public class ChanjetAuthController {


    @Autowired
    private ChanjetSpi chanjetSpi;


    @Autowired
    private RedisService redisService;

    @GetMapping("/refresh")
    public Result<Object> getInventoryClass() throws ChanjetApiException {
        chanjetSpi.refreshToken();
        return Result.OK();
    }

    @GetMapping("/setToken")
    public Result<Object> setToken(){
        redisService.add(Constants.CHANJET_TOKEN,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpc3YiLCJpc3MiOiJjaGFuamV0IiwidXNlcklkIjoiMzkwNzEzMzI1MzU2NzAyIiwib3JnSWQiOiIxMjM2NzA2NDYxNzQ4MzMyIiwiYWNjZXNzX3Rva2VuIjoiYmstNGUxZTljYzAtMjQ1OC00MjBmLTlmZDktNzc5Y2JhNTBjM2QyIiwiYXVkIjoiaXN2IiwibmJmIjoxNjkwNzc0NTQ1LCJhcHBJZCI6IjU4Iiwic2NvcGUiOiJhdXRoX2FsbCIsImlkIjoiNDMyZmU3ZDUtMWEyYS00MDBlLTg2M2EtYWNhNTNkNjFmY2ViIiwiZXhwIjoxNjkxMjkyOTQ1LCJpYXQiOjE2OTA3NzQ1NDUsIm9yZ0FjY291bnQiOiJ1eXFzcjcwcTY2YngifQ.G3LHT_n0w94qBNNCETa5WhTFRZhUW2SFo7-dpqCHx_A");
        return Result.OK();
    }
}
